package com.weiyi.mashangzhu.Roomer.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.weiyi.mashangzhu.API.API;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Roomer.Activity.RecommendActivity;
import com.weiyi.mashangzhu.Roomer.Bean.ActivityBean;

import java.util.List;

/**
 * Created by win7 on 2017/9/21.
 */

public class ThemeAdapter extends PagerAdapter {
    private Context context;
    private List<ActivityBean.DataBean> list;
    private View mCurrentView;

    public ThemeAdapter(Context context, List<ActivityBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        mCurrentView = (View) object;
    }

    public View getPrimaryItem() {
        return mCurrentView;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
//        // TODO Auto-generated method stub
        View view;
        view = View.inflate(context, R.layout.item_theme_1, null);
        ImageView bg = (ImageView) view.findViewById(R.id.bg);
        TextView title = (TextView) view.findViewById(R.id.title);
        TextView look = (TextView) view.findViewById(R.id.look);
        final TextView content = (TextView) view.findViewById(R.id.content);
        Glide.with(context).load(API.BaseApi_url + list.get(position).getAcPic()).into(bg);
        title.setText(list.get(position).getAcTitle());
        content.setText(list.get(position).getAcContent());
        look.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, RecommendActivity.class);
                intent.putExtra("info","activity");
                intent.putExtra("id", list.get(position).getId()+"");
                context.startActivity(intent);
            }
        });
        container.addView(view);
        return view;
    }
}
